def f(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0: return False
    return True

b=[]
x=int(input())
if len(str(x))!=4:
    print(0)
else:
    y=str(x)
    a=[int(y[0]),int(y[1]),int(y[2]),int(y[3]),int(y[0:2]), int(y[1:3]),int(y[2:]), int(y[0:3]), int(y[1:]),x]
    for m in a:
        if f(m):
            b.appened(m)
        if len(b)>0:
            print(max(b))
        else:
            print(0)